package com.mate.cloud.mapper;


import com.google.common.collect.Maps;
import com.mate.cloud.entity.City;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 本demo纯粹演示redis，数据库操作这里只模拟从cityMap里获取
 */
@Slf4j
@Component
public class CityMapper {

    private static Map<String, City> cityMap = Maps.newHashMap();

    static {
        cityMap.put("110100000000", new City(1L, "110100000000", "北京"));
        cityMap.put("310100000000", new City(2L, "310100000000", "上海"));
        cityMap.put("440300000000", new City(3L, "440300000000", "深圳"));
        cityMap.put("440100000000", new City(4L, "440100000000", "广州"));
    }

    public City getCity(String code) {
        City city = cityMap.get(code);
        log.info("query city from DB, code {}:, city: {}", code, city);
        return city;
    }
}
